package logger

import (
	"github.com/CIPFZ/collector/internal/config"

	"go.uber.org/zap"
)

// Debug 记录调试级别日志
func (l *zapLogger) Debug(msg string, fields ...zap.Field) {
	l.logger.Debug(msg, fields...)
}

// Info 记录信息级别日志
func (l *zapLogger) Info(msg string, fields ...zap.Field) {
	l.logger.Info(msg, fields...)
}

// Warn 记录警告级别日志
func (l *zapLogger) Warn(msg string, fields ...zap.Field) {
	l.logger.Warn(msg, fields...)
}

// Error 记录错误级别日志
func (l *zapLogger) Error(msg string, fields ...zap.Field) {
	l.logger.Error(msg, fields...)
}

// Panic 记录恐慌级别日志
func (l *zapLogger) Panic(msg string, fields ...zap.Field) {
	l.logger.Panic(msg, fields...)
}

// Fatal 记录致命级别日志
func (l *zapLogger) Fatal(msg string, fields ...zap.Field) {
	l.logger.Fatal(msg, fields...)
}

func (l *zapLogger) Debugf(format string, args ...interface{}) {
	l.logger.Sugar().Debugf(format, args...)
}

func (l *zapLogger) Infof(format string, args ...interface{}) {
	l.logger.Sugar().Infof(format, args...)
}

func (l *zapLogger) Warnf(format string, args ...interface{}) {
	l.logger.Sugar().Warnf(format, args...)
}

func (l *zapLogger) Errorf(format string, args ...interface{}) {
	l.logger.Sugar().Errorf(format, args...)
}

func (l *zapLogger) Panicf(format string, args ...interface{}) {
	l.logger.Sugar().Panicf(format, args...)
}

func (l *zapLogger) Fatalf(format string, args ...interface{}) {
	l.logger.Sugar().Fatalf(format, args...)
}

// Sync 同步日志
func (l *zapLogger) Sync() error {
	return l.logger.Sync()
}

// With 添加字段
func (l *zapLogger) With(fields ...zap.Field) Logger {
	return &zapLogger{
		logger: l.logger.With(fields...),
	}
}

// NewLoggerInterface 创建日志器接口实现
func NewLoggerInterface() (Logger, error) {
	zapLog, err := NewLogger()
	if err != nil {
		return nil, err
	}

	return &zapLogger{
		logger: zapLog,
	}, nil
}

// NewLoggerInterfaceWithConfig 根据配置创建日志器接口实现
func NewLoggerInterfaceWithConfig(cfg config.LoggerConfig) (Logger, error) {
	zapLog, err := NewLoggerWithConfig(cfg)
	if err != nil {
		return nil, err
	}

	return &zapLogger{
		logger: zapLog,
	}, nil
}
